﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
namespace QLHS
{
    public partial class frm_Report : Form
    {
        public frm_Report(int tq,string kd,string h,string m)
        {
            InitializeComponent();
            Program.connect();
            dk = kd;
            kk = tq;
            mon = m;
            hk = h;
        }
        int kk;
        string dk;
        string mon,hk;
        private void crystalReportViewer1_Load(object sender, EventArgs e)
        {
            //ReportDocument rpt = new Report.rpt_DSLop();
            //((TextObject)rpt.ReportDefinition.ReportObjects["Text9"]).Text = "Chào bạn";
            if (kk == 1)
            {
                SqlDataAdapter da = null;
                DataSet ds = new DataSet();
                Report.rpt_DSLop crp = new Report.rpt_DSLop();
                Program.con = new SqlConnection(Program.str);
                da = new SqlDataAdapter("select * from HOCSINHLOP,LOP where HOCSINHLOP.LOP = LOP.TENLOP and HOCSINHLOP.LOP=N'"+dk+"'", Program.con);
                da.Fill(ds, "HOCSINHLOP");
                if (ds.Tables["HOCSINHLOP"].Rows.Count != 0)
                {
                    crp.SetDataSource(ds.Tables["HOCSINHLOP"]);
                    crystalReportViewer1.ReportSource = crp;
                    crystalReportViewer1.Show();
                }
                else
                {
                    MessageBox.Show("Không tìm thấy dữ liệu...", "Thông Báo");
                }
            }
            else if (kk == 2)
            {
                SqlDataAdapter da = null;
                DataSet ds = new DataSet();
                Report.rpt_TBHK crp = new Report.rpt_TBHK();
                Program.con = new SqlConnection(Program.str);
                da = new SqlDataAdapter("select * from TBHOCKY", Program.con);
                da.Fill(ds, "TBHOCKY");
                if (ds.Tables["TBHOCKY"].Rows.Count != 0)
                {
                    crp.SetDataSource(ds.Tables["TBHOCKY"]);
                    crystalReportViewer1.ReportSource = crp;
                    crystalReportViewer1.Show();
                }
                else
                {
                    MessageBox.Show("Không tìm thấy dữ liệu...", "Thông Báo");
                }
            }
            else if (kk == 3)
            {
                SqlDataAdapter da = null;
                DataSet ds = new DataSet();
                Report.rpt_DiemHS crp = new Report.rpt_DiemHS();
                Program.con = new SqlConnection(Program.str);
                da = new SqlDataAdapter("select * from DIEMHOCSINH where MONHOC=N'"+mon+"'AND HOCKY=N'"+hk+"'and LOP=N'"+dk+"'", Program.con);
                da.Fill(ds, "DIEMHOCSINH");
                if (ds.Tables["DIEMHOCSINH"].Rows.Count != 0)
                {
                    crp.SetDataSource(ds.Tables["DIEMHOCSINH"]);
                    crystalReportViewer1.ReportSource = crp;
                    crystalReportViewer1.Show();
                }
                else
                {
                    MessageBox.Show("Không tìm thấy dữ liệu...", "Thông Báo");
                }
            }
            else if (kk == 4)
            {
                SqlDataAdapter da = null;
                DataSet ds = new DataSet();
                Report.rpt_BCTKM crp = new Report.rpt_BCTKM();
                Program.con = new SqlConnection(Program.str);
                da = new SqlDataAdapter("select * from TONGKETMON where MONHOC=N'" + mon + "'AND HOCKY=N'" + hk + "'", Program.con);
                da.Fill(ds, "TONGKETMON");
                if (ds.Tables["TONGKETMON"].Rows.Count != 0)
                {
                    crp.SetDataSource(ds.Tables["TONGKETMON"]);
                    crystalReportViewer1.ReportSource = crp;
                    crystalReportViewer1.Show();
                }
                else
                {
                    MessageBox.Show("Không tìm thấy dữ liệu...", "Thông Báo");
                }
            }
            else
            {
                SqlDataAdapter da = null;
                DataSet ds = new DataSet();
                Report.rpt_BCTKHK crp = new Report.rpt_BCTKHK();
                Program.con = new SqlConnection(Program.str);
                da = new SqlDataAdapter("select * from TONGKETHK where HOCKY=N'" + hk + "'", Program.con);
                da.Fill(ds, "TONGKETHK");
                if (ds.Tables["TONGKETHK"].Rows.Count != 0)
                {
                    crp.SetDataSource(ds.Tables["TONGKETHK"]);
                    crystalReportViewer1.ReportSource = crp;
                    crystalReportViewer1.Show();
                }
                else
                {
                    MessageBox.Show("Không tìm thấy dữ liệu...", "Thông Báo");
                }
            }
        }
    }
}
